package com.ztesoft.huangfu.learning.springboot.springbootwebflux.service.impl;

import com.ztesoft.huangfu.learning.springboot.springbootwebflux.entity.City;
import com.ztesoft.huangfu.learning.springboot.springbootwebflux.service.CityService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Author: huangfu.daohui
 * Date: 2018/6/12
 * Time: 19:09
 * Version: 1.0
 * Description:城市实现类
 **/
public class CityServiceImpl implements CityService {
    // 模拟数据库，存储 City 信息
    private static Map<Long, City> CITY_DB = new HashMap<>();

    public List<City> findAllCity() {
        return new ArrayList<>(CITY_DB.values());
    }

    public City findCityById(Long id) {
        return CITY_DB.get(id);
    }

    @Override
    public Long saveCity(City city) {
        city.setId(CITY_DB.size() + 1L);
        CITY_DB.put(city.getId(), city);
        return city.getId();
    }

    @Override
    public Long updateCity(City city) {
        CITY_DB.put(city.getId(), city);
        return city.getId();
    }

    @Override
    public Long deleteCity(Long id) {
        CITY_DB.remove(id);
        return id;
    }
}
